package com.xyun.task.service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xyun.task.bean.WeixinCustomer;
import com.xyun.task.dao.TaskDao;

@Service
public class TaskService
{
    @Autowired
    private TaskDao taskDao;

    public Map<?, ?> getMpacc(String weixinpk){
        Map<?, ?> result = null;
        try
        {
            result = taskDao.getMpacc(weixinpk);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       
        return result;
    }
    public List<?> getMpaccList(){
    	 List<?> list = null;
         try
         {
             list = taskDao.getMpaccList();
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
        
         return list;
    }
    /**
     * 获取全局指令列表
     * @author：	 xyun
     */
    public  List<?> getGlobOrderList(String weixinpk){
        List<?> list = null;
        try
        {
            list = taskDao.getGlobOrderList(weixinpk);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       
        return list;
    }
    public Map<?, ?> queryMenu(String weixinpk,String menukey){
        Map<?, ?> result = null;
        try
        {
            result = taskDao.queryMenu(weixinpk,menukey);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       
        return result;
    }
    /**
     * 查询客户信息
     */
    public WeixinCustomer getWxCustomer(String weixinpk,String openid){
        WeixinCustomer weixin = null;
        try
        {
        	weixin=taskDao.getWxCustomer(weixinpk,openid);
           
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        
        return weixin;
    }
    public List<WeixinCustomer> getWxCustomerList(WeixinCustomer weixinCustomer){
    	 List<WeixinCustomer> list = null;
         try
         {
             list = taskDao.getWxCustomerList(weixinCustomer);
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
        
         return list;
    }
    public boolean saveWxCustomer(WeixinCustomer weixin,String type){
        if(type.equals("0")){
            //更新
            return taskDao.updateWxCustomer(weixin);
        }else{
            //插入
            return taskDao.insertWxCustomer(weixin);
        }
    }
    public Map<?, ?> getWxEvent(String weixinpk,String event){
        Map<?, ?> result = null;
        try
        {
            result = taskDao.getWxEvent(weixinpk,event);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       
        return result;
    }
    public Map<?,?> getMaterial(String materialNo){
        Map<?, ?> result = null;
        try
        {
            result = taskDao.getMaterial(materialNo);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       
        return result;
    }
    public List<?> getMaterialImgmsgList(String materialNo){
        List<?> list = null;
        try
        {
            list = taskDao.getMaterialImgmsgList(materialNo);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       
        return list;
    }
    
    //统计每天的微信绑定保有量
    public void bindReport(){
    	taskDao.bindReport();
    }
    /**
     * 获取昨日绑定数据
     * @author：	 xyun
     * @createtime： 2016年6月27日 下午1:59:45
     * @return
     */
    public List<?> getLastBindData(){
    	return taskDao.getLastBindData();
    }
    
    public boolean isNewBind(String custno,String custno_crm){
    	Map map = taskDao.isNewBind(custno, custno_crm);
    	if(map!=null){
    		int cc =Integer.parseInt(map.get("CC").toString());
    		if(cc==0){
    			return true;
    		}
    	}
    	return false;
    }
    /**
     * 和isNewBind查询的表不一样，去掉当天重复的数据
     * @author：	 xyun
     */
    public boolean isOldBind(String certType,String certNo){
    	Map map = taskDao.isOldBind(certType, certNo);
    	if(map!=null){
    		int cc = Integer.parseInt(map.get("CC").toString());
    		if(cc==0){
    			return false;
    		}
    	}
    	return true;
    }
    public boolean addScoreLog(String certType,String certNo,String custno,String custno_crm,String mpid,String openid,String result,String remark){
    	return taskDao.addScoreLog(certType, certNo, custno, custno_crm, mpid, openid,result,remark);
    }
    public List<?> getScoreFail(){
    	return taskDao.getScoreFail();
    }
    public boolean updateScoreLog(String certType,String certNo,String mpid,String result,String remark){
    	return taskDao.updateScoreLog(certType, certNo, mpid, result, remark);
    }
}
